/*   1:    */ package org.intellij.plugins.relaxNG.xml.dom.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.codeInsight.daemon.EmptyResolveMessageProvider;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.LocalQuickFixProvider;
import com.intellij.psi.PsiElementResolveResult;
import com.intellij.psi.PsiReferenceBase.Poly;
import com.intellij.psi.ResolveResult;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xml.GenericAttributeValue;
import org.intellij.plugins.relaxNG.model.Define;
import org.intellij.plugins.relaxNG.model.resolve.DefinitionResolver;
import org.intellij.plugins.relaxNG.xml.dom.RngGrammar;
import org.intellij.plugins.relaxNG.xml.dom.RngParentRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */ 
/*  32:    */ public class DefinitionReference
/*  33:    */   extends PsiReferenceBase.Poly<XmlAttributeValue>
/*  34:    */   implements LocalQuickFixProvider, EmptyResolveMessageProvider, Function<Define, ResolveResult>
/*  35:    */ {
/*  36:    */   private final boolean a;
/*  37:    */   private final GenericAttributeValue<String> b;
/*  38:    */   
/*  39:    */   public DefinitionReference(GenericAttributeValue<String> paramGenericAttributeValue)
/*  40:    */   {
/*  41: 60 */     super(paramGenericAttributeValue.getXmlAttributeValue());
/*  42: 61 */     this.b = paramGenericAttributeValue;
/*  43: 62 */     this.a = (paramGenericAttributeValue.getParent() instanceof RngParentRef);
/*  44:    */   }
/*  45:    */   
/*  46:    */   public boolean isSoft()
/*  47:    */   {
/*  48: 67 */     return true;
/*  49:    */   }
/*  50:    */   
/*  51:    */   @NotNull
/*  52:    */   public ResolveResult[] multiResolve(boolean paramBoolean)
/*  53:    */   {
/*  54: 72 */     RngGrammar localRngGrammar = getScope();
/*  55: 73 */     if (localRngGrammar == null)
/*  56:    */     {
/*  57: 74 */       ResolveResult[] tmp12_9 = ResolveResult.EMPTY_ARRAY;
/*  58: 74 */       if (tmp12_9 == null) {
/*  59: 74 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "multiResolve" }));
/*  60:    */       }
/*  61: 74 */       return tmp12_9;
/*  62:    */     }
/*  63: 77 */     Set localSet = DefinitionResolver.resolve(localRngGrammar, (String)this.b.getValue());
/*  64: 78 */     if ((localSet == null) || (localSet.size() == 0))
/*  65:    */     {
/*  66: 78 */       ResolveResult[] tmp80_77 = ResolveResult.EMPTY_ARRAY;
/*  67: 78 */       if (tmp80_77 == null) {
/*  68: 78 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "multiResolve" }));
/*  69:    */       }
/*  70: 78 */       return tmp80_77;
/*  71:    */     }
/*  72: 80 */     ResolveResult[] tmp125_122 = ((ResolveResult[])ContainerUtil.map2Array(localSet, ResolveResult.class, this));
/*  73: 80 */     if (tmp125_122 == null) {
/*  74: 80 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "multiResolve" }));
/*  75:    */     }
/*  76: 80 */     return tmp125_122;
/*  77:    */   }
/*  78:    */   
/*  79:    */   @Nullable
/*  80:    */   public RngGrammar getScope()
/*  81:    */   {
/*  82: 85 */     RngGrammar localRngGrammar = (RngGrammar)this.b.getParentOfType(RngGrammar.class, true);
/*  83: 86 */     if (localRngGrammar == null) {
/*  84: 87 */       return null;
/*  85:    */     }
/*  86: 89 */     if (this.a) {
/*  87: 90 */       localRngGrammar = (RngGrammar)localRngGrammar.getParentOfType(RngGrammar.class, true);
/*  88:    */     }
/*  89: 92 */     return localRngGrammar;
/*  90:    */   }
/*  91:    */   
/*  92:    */   public ResolveResult fun(Define paramDefine)
/*  93:    */   {
/*  94: 96 */     XmlElement localXmlElement = (XmlElement)paramDefine.getPsiElement();
/*  95: 97 */     assert (localXmlElement != null);
/*  96: 98 */     return new PsiElementResolveResult(localXmlElement);
/*  97:    */   }
/*  98:    */   
/*  99:    */   @NotNull
/* 100:    */   public Object[] getVariants()
/* 101:    */   {
/* 102:103 */     RngGrammar localRngGrammar = getScope();
/* 103:104 */     if (localRngGrammar == null)
/* 104:    */     {
/* 105:105 */       ResolveResult[] tmp12_9 = ResolveResult.EMPTY_ARRAY;
/* 106:105 */       if (tmp12_9 == null) {
/* 107:105 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "getVariants" }));
/* 108:    */       }
/* 109:105 */       return tmp12_9;
/* 110:    */     }
/* 111:108 */     Map localMap = DefinitionResolver.getAllVariants(localRngGrammar);
/* 112:109 */     if ((localMap == null) || (localMap.size() == 0))
/* 113:    */     {
/* 114:109 */       Object[] tmp68_65 = ArrayUtil.EMPTY_OBJECT_ARRAY;
/* 115:109 */       if (tmp68_65 == null) {
/* 116:109 */         throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "getVariants" }));
/* 117:    */       }
/* 118:109 */       return tmp68_65;
/* 119:    */     }
/* 120:111 */     Object[] tmp125_120 = ContainerUtil.mapNotNull(localMap.values(), new Function()).toArray();
/* 121:111 */     if (tmp125_120 == null) {
/* 122:111 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "getVariants" }));
/* 123:    */     }
/* 124:111 */     return tmp125_120;
/* 125:    */   }
/* 126:    */   
/* 127:    */   public LocalQuickFix[] getQuickFixes()
/* 128:    */   {
/* 129:134 */     XmlTag localXmlTag = (XmlTag)PsiTreeUtil.getParentOfType(getElement(), XmlTag.class);
/* 130:135 */     assert (localXmlTag != null);
/* 131:136 */     RngGrammar localRngGrammar = (RngGrammar)this.b.getParentOfType(RngGrammar.class, true);
/* 132:137 */     if (localRngGrammar != null) {
/* 133:138 */       return new LocalQuickFix[] { new CreatePatternFix(this) };
/* 134:    */     }
/* 135:140 */     return LocalQuickFix.EMPTY_ARRAY;
/* 136:    */   }
/* 137:    */   
/* 138:    */   @NotNull
/* 139:    */   public String getUnresolvedMessagePattern()
/* 140:    */   {
/* 141:145 */     String tmp2_0 = "Unresolved pattern reference ''{0}''";
/* 142:145 */     if (tmp2_0 == null) {
/* 143:145 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/xml/dom/impl/DefinitionReference", "getUnresolvedMessagePattern" }));
/* 144:    */     }
/* 145:145 */     return tmp2_0;
/* 146:    */   }
/* 147:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.xml.dom.impl.DefinitionReference

 * JD-Core Version:    0.7.0.1

 */